package com.battery.system.service.battery.impl;

import java.util.List;

import com.battery.system.domain.BO.MerchantBO;
import com.battery.system.domain.Merchant;
import com.battery.system.mapper.MerchantMapper;
import com.battery.system.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.battery.system.mapper.MerchantInstallMapper;
import com.battery.system.domain.MerchantInstall;
import com.battery.system.service.battery.IMerchantInstallService;
import com.battery.common.core.text.Convert;
import org.springframework.transaction.annotation.Transactional;

/**
 * 商户配置Service业务层处理
 *
 * @author battery
 * @date 2021-01-22
 */
@Service
public class MerchantInstallServiceImpl extends BaseServiceImpl<MerchantInstall> implements IMerchantInstallService {
    @Autowired
    private MerchantInstallMapper merchantInstallMapper;


    @Autowired
    private MerchantMapper merchantMapper;

    /**
     * 查询商户配置
     *
     * @param merchantId 商户配置ID
     * @return 商户配置
     */
    @Override
    public MerchantInstall selectMerchantInstallById(String merchantId) {
        return merchantInstallMapper.selectMerchantInstallById(merchantId);
    }

    /**
     * 查询商户配置列表
     *
     * @param merchantInstall 商户配置
     * @return 商户配置
     */
    @Override
    public List<MerchantInstall> selectMerchantInstallList(MerchantInstall merchantInstall) {
        return merchantInstallMapper.selectMerchantInstallList(merchantInstall);
    }

    /**
     * 新增商户配置
     *
     * @param merchantInstall 商户配置
     * @return 结果
     */
    @Override
    public int insertMerchantInstall(MerchantInstall merchantInstall) {
        return merchantInstallMapper.insertMerchantInstall(merchantInstall);
    }

    /**
     * 修改商户配置
     *
     * @param merchantInstall 商户配置
     * @return 结果
     */
    @Override
    public int updateMerchantInstall(MerchantInstall merchantInstall) {
        return merchantInstallMapper.updateMerchantInstall(merchantInstall);
    }

    /**
     * 删除商户配置对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteMerchantInstallByIds(String ids) {
        return merchantInstallMapper.deleteMerchantInstallByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除商户配置信息
     *
     * @param merchantId 商户配置ID
     * @return 结果
     */
    @Override
    public int deleteMerchantInstallById(String merchantId) {
        return merchantInstallMapper.deleteMerchantInstallById(merchantId);
    }

    /**
     * 商户设置
     *
     * @param merchantBO
     * @return
     */
    @Transactional
    @Override
    public int setUpMerchant(MerchantBO merchantBO) {

        MerchantInstall merchantInstall1Update = new MerchantInstall();
        merchantInstall1Update.setMerchantId(merchantBO.getMerchantId());
        merchantInstall1Update.setTxBrokerage(merchantBO.getTxBrokerage());
        merchantInstall1Update.setTxMinPermit(merchantBO.getTxMinPermit());
        merchantInstall1Update.setDeatilAbility(merchantBO.getDeatilAbility());
        merchantInstall1Update.setCashoutAbility(merchantBO.getCashoutAbility());
        merchantInstallMapper.updateByPrimaryKeySelective(merchantInstall1Update);

        Merchant merchantUpdate = new Merchant();
        merchantUpdate.setId(merchantBO.getMerchantId());
        merchantUpdate.setFrozenMoney(merchantBO.getFrozenMoney());
        merchantUpdate.setCashoutMoney(merchantBO.getCashoutMoney());
        merchantMapper.updateByPrimaryKeySelective(merchantUpdate);

        return 1;
    }
}
